@page
@using LLama.Web.Common;

@model IndexModel
@{
    ViewData["Title"] = "Home";
}

@Html.AntiForgeryToken()
<div class="d-flex flex-row h-100 pt-1 pb-1">

    <div id="sidebar" class="d-flex flex-column h-100 pe-1 w-25">
        <div class="d-flex flex-column overflow-auto">
            <form id="SessionParameters">
                <div class="d-flex flex-column m-1">
                    <div class="d-flex flex-column mb-2">
                        <div class="form-floating">
                            @Html.DropDownListFor(m => m.SessionConfig.Model, new SelectList(Model.Options.Models, "Name", "Name"), new { @class = "form-select prompt-control", required = "required", autocomplete = "off" })
                            @Html.LabelFor(m => m.SessionConfig.Model)
                        </div>
                    </div>
                    <div class="d-flex flex-column mb-2">
                        <div class="form-floating">
                            @Html.DropDownListFor(m => m.SessionConfig.ExecutorType, Html.GetEnumSelectList<LLamaExecutorType>(), new { @class = "form-select prompt-control", required = "required", autocomplete = "off" })
                            @Html.LabelFor(m => m.SessionConfig.ExecutorType)
                        </div>
                    </div>
                    <div class="d-flex flex-column mb-2">
                        <div class="form-floating">
                            @Html.TextAreaFor(m => Model.SessionConfig.Prompt, new { @class = "form-control prompt-control", rows = 8 })
                            @Html.LabelFor(m => m.SessionConfig.Prompt)
                        </div>
                    </div>

                    <div class="d-flex flex-column mb-2">
                        <div class="form-floating">
                            @Html.TextBoxFor(m => Model.SessionConfig.AntiPrompt, new { @type = "text", @class = "form-control prompt-control" })
                            @Html.LabelFor(m => m.SessionConfig.AntiPrompt)
                        </div>
                    </div>

                    <div class="d-flex flex-column mb-2">
                        <div class="form-floating">
                            @Html.TextBoxFor(m => Model.SessionConfig.OutputFilter, new { @type = "text", @class = "form-control prompt-control" })
                            @Html.LabelFor(m => m.SessionConfig.OutputFilter)
                        </div>
                    </div>

                    <div class="accordion" id="accordionSideBar">
                        <div class="accordion-item">
                            <h2 class="accordion-header">
                                <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseParameters" aria-expanded="false" aria-controls="collapseParameters">
                                    Parameters
                                </button>
                            </h2>
                            <div id="collapseParameters" class="accordion-collapse collapse" data-bs-parent="#accordionSideBar">
                                <div class="accordion-body">
                                    @{
                                        await Html.RenderPartialAsync("_Parameters", Model.InferenceOptions);
                                    }
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="d-flex flex-grow-1"></div>
        <div class="m-1">
            <button class="btn btn-primary w-100" type="button" id="load">
                <div class="d-flex align-items-center justify-content-center">
                    <img class="spinner me-2" style="display:none" src="~/image/loading.gif" width="20" />
                    Begin Session
                </div>
            </button>
            <button class="btn btn-danger w-100" type="button" id="unload" style="display:none">End Session</button>
        </div>
    </div>

    <div class="d-flex flex-column h-100 w-75">
        <div class="section-head">
        </div>

        <div id="scroll-container" class="section-content">
            <div id="output-container" class="d-flex flex-column gap-1 p-1">
            </div>
        </div>

        <div class="input-group mt-2">
            <textarea id="input" type="text" class="form-control" value="what is a tree?" style="resize:none" rows="2">What is an apple?</textarea>
            <button class="btn btn-primary input-control px-4" type="button" id="send" disabled="disabled" autocomplete="off">
                Send
                <i class="bi bi-caret-right-fill"></i>
            </button>
        </div>

    </div>
</div>

@{
    await Html.RenderPartialAsync("_ChatTemplates");
}

@section Scripts {
    <script src="~/js/sessionConnectionChat.js"></script>
    <script>
        createConnectionSessionChat();
    </script>
}